package com.ctshk.rpc.goods.mapper.provider;

import org.apache.ibatis.jdbc.SQL;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.goods.dto.CommodityClassificationDTO;
import com.ctshk.rpc.goods.req.CommodityClassificationPageReq;

/**
 * 商品分类-分页列表查询
 * @author 姜斌文
 * @since 2021-04-08
 */
public class CommodityClassificationProvider {

    public String findCommodityClassificationByCondition(IPage<CommodityClassificationDTO> page,CommodityClassificationPageReq pageReq) {
    	String sql = new SQL() {{
                SELECT("t.id, t.classification_name, t.classification_level, t.icon, t.is_display, t.parent_id, t.status, t.sort");
                FROM("t_commodity_classification t");
                if(pageReq.getUserIds() != null){
                    WHERE("t.create_id in (${pageReq.userIds})");
                }
                WHERE("t.is_deleted = 0");
                if (null == pageReq.getCurrentLevelPage()) {
                	pageReq.setCurrentLevelPage(1);
                }
            if (pageReq.getCurrentLevelPage() == 1) {
                WHERE("t.classification_level = #{pageReq.currentLevelPage} ");
            } else if (pageReq.getCurrentLevelPage() == 2 && null != pageReq.getId()){
                WHERE("t.classification_level = #{pageReq.currentLevelPage} AND t.parent_id = #{pageReq.id}");
            }
                ORDER_BY("t.sort ASC");
            }}.toString();
            return sql;
    }
}
